package handlers;

import entity.Entity;
import map.GameMap;
import map.GameWorld;
import map.Position;
import pausing.Pauseable;

public class TeleportHandler extends Pauseable {
	
	private GameWorld world;
	private Entity entity;
	private String mapTo;
	
	public TeleportHandler(String mapTo, Entity entity) {
		
		this.world = GameWorld.getInstance();
		this.entity = entity;
		this.mapTo = mapTo;
	}
	
	public void teleport() {
		
		GameMap map = world.getMap(mapTo);
		
		if(map != null && entity.equals(world.getAvatar())) {
			
			world.getCurrentMap().removeEntity(entity.getPosition());
			world.getCurrentMap().getAEAssoc().updateEntity(entity, new Position(-1, -1));
			world.getCurrentMap().uninitializeAI();
			map.addEntity(entity, map.getSpawn());
			entity.setPosition(new Position(map.getSpawn()));
			world.setCurrentMap(map);
		}
	}
}
